package com.jevons.geo_edit.model;


import com.jevons.geo_edit.R;
import com.jevons.geo_edit.constant.GisGeometryType;
import com.jevons.muffin.util.UuidUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Copyright 2020 JxGIS
 *
 * @file GisLayer
 * @auth linaisheng
 * Created on 2023/6/9.
 * Description：
 */
public class GisLayer implements Serializable {

    private String id;
    private String projectId;


    private String layerName;

    private int type = GisGeometryType.Point.getType();

    private String fieldTempId;
    private int sort;     //排序

    private String layerStyle;      //图层样式
    private String labelStyle;      //标注样式

    private GisLayerStyle myLayerStyle;

    private List<GisGeometry> geometryList;
    private ArrayList<GisField> fieldList;


    private String versionId;
    private boolean layerVisible = true;

    public GisLayer(String id) {
        this.id = id;
    }

    public GisLayer(String projectId, GisGeometryType geometryType, String layerName) {
        this.id = UuidUtils.generateId();
        this.projectId = projectId;
        this.type = geometryType.getType();
        this.layerName = layerName;
        restLayerStyle();
    }

    public GisLayer(String id, String projectId, String layerName, int type, String fieldTempId, int sort,
                    String layerStyle, String labelStyle) {
        this.id = id;
        this.projectId = projectId;
        this.layerName = layerName;
        this.type = type;
        this.fieldTempId = fieldTempId;
        this.sort = sort;
        this.layerStyle = layerStyle;
        this.labelStyle = labelStyle;
    }

    public String getId() {
        return id;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    public int getType() {
        return type;
    }

    public GisGeometryType getGeometryType() {
        return GisGeometryType.getByType(type);
    }

    public String getLayerName() {
        return layerName;
    }

    public void setLayerName(String layerName) {
        this.layerName = layerName;
    }

    public List<GisGeometry> getGeometryList() {
        return geometryList;
    }

    public void setGeometryList(List<GisGeometry> geometryList) {
        this.geometryList = geometryList;
    }

    public void setFieldList(ArrayList<GisField> fieldList) {
        this.fieldList = fieldList;
    }

    public ArrayList<GisField> getFieldList() {
        return fieldList;
    }

    public String getLayerStyle() {
        return layerStyle;
    }

    public void setLayerStyle(String layerStyle) {
        this.layerStyle = layerStyle;
    }

    public void setMyLayerStyle(GisLayerStyle myLayerStyle) {
        this.myLayerStyle = myLayerStyle;
    }

    public GisLayerStyle getMyLayerStyle() {
        if (myLayerStyle == null) {
            myLayerStyle = new GisLayerStyle(projectId, id);
        }
        return myLayerStyle;
    }

    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    public void restLayerStyle() {
        this.myLayerStyle = new GisLayerStyle(projectId, id);
    }

    public boolean isLayerVisible() {
        return layerVisible;
    }

    public void setLayerVisible(boolean layerVisible) {
        this.layerVisible = layerVisible;
    }

    public static int getPointStyleRes(int pointType, int pointStyle) {
        if (pointType == 0) {
            if (pointStyle == 0) {
                return R.mipmap.icon_geo_point_type_yx_fill;
            } else {
                return R.mipmap.icon_geo_point_type_yx;
            }
        } else if (pointType == 1) {
            if (pointStyle == 0) {
                return R.mipmap.icon_geo_point_type_zfx_fill;
            } else {
                return R.mipmap.icon_geo_point_type_zfx;
            }
        } else if (pointType == 2) {
            if (pointStyle == 0) {
                return R.mipmap.icon_geo_point_type_szx_fill;
            } else {
                return R.mipmap.icon_geo_point_type_szx;
            }
        } else if (pointType == 3) {
            if (pointStyle == 0) {
                return R.mipmap.icon_geo_point_type_jcx_fill;
            } else {
                return R.mipmap.icon_geo_point_type_jcx;
            }
        } else if (pointType == 4) {
            if (pointStyle == 0) {
                return R.mipmap.icon_geo_point_type_lx_fill;
            } else {
                return R.mipmap.icon_geo_point_type_lx;
            }
        } else if (pointType == 5) {
            if (pointStyle == 0) {
                return R.mipmap.icon_geo_point_type_wjx_fill;
            } else {
                return R.mipmap.icon_geo_point_type_wjx;
            }
        }  else if (pointType == 6) {
            if (pointStyle == 0) {
                return R.mipmap.icon_geo_point_type_sjx_fill;
            } else {
                return R.mipmap.icon_geo_point_type_sjx;
            }
        } else {
            return R.mipmap.icon_geo_point_type_yx_fill;
        }
    }


    public static int getPolygonStyleRes(int polygonType) {
        if (polygonType == 0) {
            return R.mipmap.img_gis_map_polygon_pattern_style_1;
        } else if (polygonType == 1) {
            return R.mipmap.img_gis_map_polygon_pattern_style_2;
        } else if (polygonType == 2) {
            return R.mipmap.img_gis_map_polygon_pattern_style_3;
        } else {
            return R.mipmap.img_gis_map_polygon_pattern_style_1;
        }
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        GisLayer gisLayer = (GisLayer) o;
        return Objects.equals(id, gisLayer.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}